/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GamePlay;

import FrameWork.*;
import FrameWork.Audio.RSAudio;


import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;


/**
*
 * @author ThanhTri
 */
public class State_MenuInGame extends IState{ 
    int m_OldKey = 0;
    private State_MainGame m_MainGame;
    private Sprite m_Dialog;
    private Font_Large m_Font;
    private int m_Chose;
    private Sprite m_Ball;
    Rectangle[] m_RectButton = new Rectangle[3];
    public State_MenuInGame (IPlay _Play,State_MainGame _MainGame){
        super(_Play);         
        
        m_MainGame = _MainGame;
        m_IDState = Global.STATE_MENUINGAME;            
        m_Chose = 0;
        
        try {
            m_Ball = new Sprite (Image.createImage("/Image/ball.png"),
                                60, 60);
            m_Dialog = new Sprite (Image.createImage("/Image/dialog.png"),
                            204, 235);
            m_Font = (Font_Large) RSFont.getRS().getLarge();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        for(int i =0; i<3; i++)
            m_RectButton[i] = new Rectangle(27 + i*63, 186, 60, 60);
    }
    public void PointerPressed(int x, int y){
        for(int i =0; i<3; i++){
            if(m_RectButton[i].Intersects(new Point(x,y))){
                m_Chose = i+1;
                RSAudio.getRS().PlayExplosion();
                if(m_Chose==1){
                     m_MainGame.getPlay().setNextState(
                      new State_Menu(m_Play));
                 }
                 if(m_Chose==2){
                     //Level.get().setCurLevel(i);
                     m_MainGame.getPlay().setNextState(
                      new State_Loading(m_Play));
                 }
                 if(m_Chose==3){
                     m_MainGame.setIDchoosed(0);
                     m_MainGame.m_iMenu = false;
                 }
            }
        }
    }
    public void KeyPressed (int _Keycode){
        switch(_Keycode)
        {
            // <editor-fold defaultstate="collapsed"  desc="Key : LEFT-RIGHT-UP-DOWN">
            case GameCanvas.RIGHT_PRESSED:
                if (m_OldKey == 0){
                    m_Chose ++;
                    RSAudio.getRS().PlayBubble();
                    if(m_Chose>3){
                        m_Chose = 3;
                    }
                 }
                
                break;
            case GameCanvas.LEFT_PRESSED:
                if(m_OldKey == 0){
                    RSAudio.getRS().PlayBubble();
                     m_Chose --;
                     if(m_Chose<1){
                        m_Chose = 1;
                    }
                }
                break;     
            // </editor-fold>  
             case GameCanvas.FIRE_PRESSED:
                 if(m_Chose!=0){
                     RSAudio.getRS().PlayExplosion();
                 }
                 if(m_Chose==1){
                     m_MainGame.getPlay().setNextState(
                      new State_Menu(m_Play));
                 }
                 if(m_Chose==2){
                     m_MainGame.getPlay().setNextState(
                      new State_Loading(m_Play));
                 }
                 if(m_Chose==3){
                     m_MainGame.setIDchoosed(0);
                     m_MainGame.m_iMenu = false;
                 }
                break;     
        }
        m_OldKey = _Keycode;
    }
    public void Init (){
        
    }
    public void Update (float _Time){
    }
    
    public void Render (){
        m_Dialog.setPosition(18, 20);
        m_Dialog.paint(m_Graphics);
        m_Font.DrawString("--Pause--", 80, 140, m_Graphics);
        
        if(m_Chose==1){
            m_Ball.setFrame(1);
        }else{
            m_Ball.setFrame(0);
        }
        
        m_Ball.setPosition(27, 186);
        m_Ball.paint(m_Graphics);
        m_Font.DrawString("Menu", 38, 206, m_Graphics);
        
         if(m_Chose==2){
            m_Ball.setFrame(1);
        }else{
            m_Ball.setFrame(0);
        }
         
        m_Ball.setPosition(90, 186);
        m_Ball.paint(m_Graphics);
        m_Font.DrawString("again", 96, 206, m_Graphics);
        
        if(m_Chose==3){
            m_Ball.setFrame(1);
        }else{
            m_Ball.setFrame(0);
        }
        m_Ball.setPosition(153, 186);
        m_Ball.paint(m_Graphics);
        m_Font.DrawString("resume", 154, 206, m_Graphics);
    }
    public void Destroy (){        
        m_Dialog = null;       
        m_Ball = null;
    }    
}
